'use strict';
/* Controllers */
app.controller('moodCtrl', ['$scope', '$rootScope', 'apiService', 'toaster', 'ngDialog', function ($scope, $rootScope, apiService, toaster, ngDialog) {
    $scope.article = {
        memberId: $rootScope.userObj['id'],
        content: '文章内容'
    }

    // 添加文章
    $scope.addArticle = function () {
        $scope.btn_disabled = true;
        apiService.post({
            modelName: 'mood',
            apiName: 'addMoodDB'
        }, $scope.article, function (data) {
            $scope.btn_disabled = false;
            if (data.code == 200) {
                toaster.pop('success', '提示', data['msc']);
                $scope.article = {
                    memberId: $rootScope.userObj['id'],
                    content: '文章内容'
                }
            } else {
                toaster.pop('error', '提示', data['msc']);
            }
        }, function (err) {
            $scope.btn_disabled = false;
            toaster.pop('error', '提示', '服务器出小差咯...');
        });
    }


    // 删除
    $scope.deleteItem=function(obj,index){
        // 对话框
        $scope.dialog = {
            title: '提示',
            content: '真的要删除吗?'
        };
        ngDialog.openConfirm({
            template: '/tpl/dialog.html',
            className: 'ngdialog-theme-plain',
            scope: $scope
        }).then(function (value) {
            if (value['statu'] == true) {
                apiService.post({
                    modelName: 'mood',
                    apiName: 'delMoodDB'
                }, obj, function (data) {
                    if (data.code == 200) {
                        $scope.pageData.splice(index,1);
                        toaster.pop('success', '提示', data['msc']);
                    } else {
                        toaster.pop('error', '提示', data['msc']);
                    }
                }, function (err) {
                    toaster.pop('error', '提示', '服务器出小差咯...');
                });
            }
        });
    }



    // 获取心情列表
    $scope.mood_find_obj={
        memberId: $rootScope.userObj['id']
    };
    apiService.post({
        modelName: 'mood',
        apiName: 'getListByMem'
    }, $scope.mood_find_obj, function (data) {
        if (data.code == 200) {
            $scope.pageData=data['data'];
        } else {
            toaster.pop('error', '提示', data['msc']);
        }
    }, function (err) {
        toaster.pop('error', '提示', '服务器出小差咯...');
    });


}]);